home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7142 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to tell if a file exists in C
  5. Date: Sat, 17 Feb 96 19:51:44 GMT
  6. Organization: none
  7. Message-ID: <824586704snz@genesis.demon.co.uk>
  8. References: <823685019.AA00170@escan.demon.co.uk> <4g3dh7$co6@linet06.li.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4g3dh7$co6@linet06.li.net> sbda@newshost.li.net "sbda" writes:
  15.  
  16. >Here's another way - it's ANSI C - so it should work on all C compilers 
  17. >and on all OSes:
  18. >
  19. >/*---------------------------------------*/
  20. >FILE *fp;
  21. >
  22. >  fp = fopen("filename.ext", "r");
  23. >
  24. >  if (fp == NULL) puts("File not found");
  25. >/*---------------------------------------*/
  26. >
  27. >        If the filespec doesn't exist, fp will be set to NULL. If it does 
  28. >exist, then fp will contain a non-NULL (non-zero) value.
  29.  
  30. That of course tests whether a file exists and is readable. A file that
  31. exists but is, say, only writable would fail that test.
  32.  
  33. -- 
  34. -----------------------------------------
  35. Lawrence Kirby | fred@genesis.demon.co.uk
  36. Wilts, England | 70734.126@compuserve.com
  37. -----------------------------------------
  38.